#ifndef THREAD_H
#define THREAD_H

#include "def.h"

class Thread : public QThread
{
    Q_OBJECT
public:
    explicit Thread(QObject *parent = 0);
     void setDB(QSqlDatabase db);
     void setDevice(Device dev);
     void insert();
     QString read_data(char* s, QTcpSocket& socket);
     QString read_one(char* s, QTcpSocket& socket);
     bool connect(QTcpSocket& socket);
     void sleep(long sec);
     void test();
     void analysis();
     void automaticalTuning();
     void Stop(bool flag);
     void setFix();
     void setAutoDev();
     double getDcpGain();
     double getProjector();
     void init();
     bool checkStart();
     void setDcpGain(double v);
     void setLampCurrent(double v);
    void dolaser();
    void read_XYZ(char *s, QTcpSocket& socket);
    void doExcel();
    void setTestModel(int testModel);
    void TestWanda();
    bool CheckWanda();
    bool CheckServer();
    void TestServer();
protected:
    void run();
    void initDeviceHost();


 signals:
    void send_msg(const QString str);
    void send_progress_value(const int value);
    void log_info(const QString str);
    void proc_sql(const QString sql);
public slots:
    void recv_msg(const QString msg);
private:
    Device device;
    QSqlDatabase db;
    QTcpSocket socket;

    bool read_xy(char*s, float&x, float&y, QTcpSocket& socket);

    float white_ftl, wx, wy, temper_c, temper_f, w_cct,
        red_ftl, rx, ry, green_ftl, gx, gy,
        blue_ftl, bluex, bluey, l_spl, r_spl,
        c_spl, lfe_spl, ls_spl, rs_spl,
        ll_spl, rl_spl;
    QString cinema_name, cinema_hall, dev_ip;
    QTime s_time, e_time;
    QDateTime stime, etime;
     unsigned int dev_port;
    Fix fix;
    AutoTuneDev auto_dev;

    DoHttp http;
    QString response;
    float using_time = 0.0f, power = 0.0f, power_w=0.0f, current=0.0f, dcp_gain = 0.0f;
    QList<DeviceHost> device_host_list;
    StdValue std;
    QList<TestSplValue> spl_list;
    TestSplValue splValue;
    AutoTuningParameter auto_parameter;
    AutoDevice auto_device_projector;
    AutoDevice auto_device_dcp;
    QString projectorIP;
    XYZ xyz;
    Laser laser;
    QMutex mutex;
    volatile bool flag ;
    volatile bool stopped;
    enum {WANDA_MODEL, LEONIS_MODEL, SERVER_MODEL} test_model;

};

#endif // THREAD_H
